--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_CPT_TVATAUX AS (SELECT * FROM &erp.CPT_TVATAUX WHERE 1=2);




DELETE FROM se_CPT_TVATAUX;

 INSERT INTO se_CPT_TVATAUX
 (SELECT SubStr(id,1,1) tvatiers_cod,
         SubStr(id,2,1) tvaart_cod,
         0 enreg_id,
         taux/100 tva_tx,
         NULL sufimput
    FROM uv_ctvas) ;


 UPDATE se_CPT_TVATAUX tf SET enreg_id=(select enreg_id FROM &erp.CPT_TVATAUX f WHERE f.tvatiers_cod=tf.tvatiers_cod AND f.tvaart_cod=tf.tvaart_cod) ;
 UPDATE se_CPT_TVATAUX tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('tvaart_cod@tvatiers_cod','CPT_TVATAUX','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source,tvatiers_cod, tvaart_cod, enreg_id, tva_tx, sufimput
FROM (
  SELECT 'uv' source ,g.* FROM se_CPT_TVATAUX g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.CPT_TVATAUX g
  )
GROUP BY  tvatiers_cod, tvaart_cod, enreg_id, tva_tx, sufimput
HAVING Count(1)!=2) r
ORDER BY tvatiers_cod, tvaart_cod;